package com.hdjk.view.callback;

import android.text.TextUtils;

import com.lst.projectlib.entity.Msg;
import com.zhy.http.okhttp.callback.Callback;

import org.json.JSONObject;

import okhttp3.Response;

/**
 * Created by Admin on 2017/11/6.
 */

public abstract class GetUpdateInfoCallback extends Callback<Msg> {
    @Override
    public Msg parseNetworkResponse(Response response, int id)
            throws Exception {
        Msg msg = new Msg();
        String result = response.body().string();

        String[] resultData = new String[]{"", "", "", "", ""};
        if (!TextUtils.isEmpty(result)) {
            try {
                JSONObject rootObject = new JSONObject(result);
                if (!rootObject.isNull("Android")) {
                    JSONObject json = rootObject.getJSONObject("Android");

                    if (!json.isNull("Remark")) {
                        resultData[0] = json.getString("Remark");
                    }

                    if (!json.isNull("Required")) {
                        resultData[1] = json.getString("Required");
                    }

                    if (!json.isNull("Url")) {
                        resultData[2] = json.getString("Url");
                    }

                    if (!json.isNull("UpdateTime")) {
                        resultData[3] = json.getString("UpdateTime");
                    }

                    if (!json.isNull("Version")) {
                        resultData[4] = json.getString("Version");
                    }
                }
                msg.setSuccess(true);
            } catch (Exception e) {
            }
        }
        msg.setData(resultData);
        return msg;
    }
}